<?
set_time_limit(9999999);
/***************************************************************************

*                            Dolphin Smart Community Builder

*                              -----------------

*     begin                : Mon Mar 23 2006

*     copyright            : (C) 2006 BoonEx Group

*     website              : http://www.boonex.com/

* This file is part of Dolphin - Smart Community Builder

*

* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License. 

* http://creativecommons.org/licenses/by/3.0/

*

* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;

* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

* See the Creative Commons Attribution 3.0 License for more details. 

* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin, 

* see license.txt file; if not, write to marketing@boonex.com

***************************************************************************/
 
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );

echo "START .....<br /><br />";

echo "UPDATING DATABASE .....<br /><br />";
 
db_res(" 
INSERT INTO  `modzzz_point_field_mapping` (`unit`, `table`, `id_field`, `owner_field`) VALUES 
 ('modzzz_location','modzzz_location_main','id','author_id') 
");
 

 
$iCategId = (int)db_value("SELECT `id` FROM `sys_options_cats` WHERE  `name`='Location'");

db_res("  
INSERT INTO `sys_options` (`Name`, `VALUE`, `kateg`, `desc`, `Type`, `check`, `err_text`, `order_in_kateg`, `AvailableValues`) VALUES 
('modzzz_location_points_activate', '', $iCategId, 'Activate Points for Locations', 'checkbox', '', '', '0', '') 
");


$iLangCategId = db_value("SELECT `ID` FROM `sys_localization_categories` WHERE `Name` = 'Modzzz Point'");

$resLang = db_res("SELECT * FROM `sys_localization_languages`");

$arrLang = array();
$iter = 0;
while($arr = mysql_fetch_array($resLang) )
{
	$arrLang[$iter] = (int)$arr['ID'];
	$iter++;
}
 

$arrLanNewKeys = array(	
 
'_modzzz_point_location_add_desc' => 'Post a Directory Location',
'_modzzz_point_location_delete_desc' => 'Delete a Directory Location',
'_modzzz_point_location_comment_add_desc' => 'Comment left on your Directory Location',
'_modzzz_point_location_comment_owner_add_desc' => 'Comment on a Directory Location',
'_modzzz_point_location_comment_delete_desc' => 'Delete a Directory Location Comment',
'_modzzz_point_location_rate_desc' => 'Rate a Directory Location',
'_modzzz_point_location_owner_rate_desc' => 'Rating left on your Directory Location',
'_modzzz_point_location_comment_rate_desc' => 'Vote on a Directory Location Comment',
'_modzzz_point_location_comment_owner_rate_desc' => 'Vote left on your Directory Location Comment',
 
);

 
foreach($arrLanNewKeys as $eachKey=>$eachVal)
{

	if($iExists = (int)db_value("SELECT `ID` FROM `sys_localization_keys` WHERE `Key`='{$eachKey}'"))
		continue;

	db_res("INSERT INTO `sys_localization_keys` SET `IDCategory`=$iLangCategId, `Key`='{$eachKey}';");

	$iInsertID = mysql_insert_id( );
	foreach( $arrLang as $iLanguage)
		db_res("INSERT INTO `sys_localization_strings` SET  `IDKey`={$iInsertID}, `IDLanguage`='{$iLanguage}', `String`='$eachVal';");
}
  
$res = db_res("SELECT `id` FROM  `modzzz_point_levels`");
while($arr = mysql_fetch_array($res)){
	$iId = $arr['id'];
	 db_res("INSERT INTO `modzzz_point_main` ( `level`, `group`, `unit`, `action`, `value`, `limit`, `desc`, `active`, `action_type`) VALUES
		('$iId', 'Location', 'modzzz_location', 'add', 2, 100, '_modzzz_point_location_add_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'delete', 2, 0, '_modzzz_point_location_delete_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'commentPost', 2, 100, '_modzzz_point_location_comment_add_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'comment_owner_add', 2, 100, '_modzzz_point_location_comment_owner_add_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'comment_owner_rate', 2, 100, '_modzzz_point_location_comment_owner_rate_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'commentRemoved', 2, 0, '_modzzz_point_location_comment_delete_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'rate', 2, 100, '_modzzz_point_location_rate_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'owner_rate', 2, 100, '_modzzz_point_location_owner_rate_desc', 1, 'standard'),
		('$iId', 'Location', 'modzzz_location', 'commentRated', 2, 100, '_modzzz_point_location_comment_rate_desc', 1, 'standard') 
	"); 
}

 
$iHandler = db_value("SELECT `id` FROM `sys_alerts_handlers` WHERE `name`='modzzz_point'"); 
db_res("
INSERT INTO `sys_alerts` VALUES   
(NULL, 'modzzz_location', 'comment_owner_rate', $iHandler),
(NULL, 'modzzz_location', 'commentRated', $iHandler),
(NULL, 'modzzz_location', 'owner_rate', $iHandler),
(NULL, 'modzzz_location', 'rate', $iHandler),
(NULL, 'modzzz_location', 'commentRemoved', $iHandler),
(NULL, 'modzzz_location', 'comment_owner_add', $iHandler),
(NULL, 'modzzz_location', 'commentPost', $iHandler),
(NULL, 'modzzz_location', 'delete', $iHandler),
(NULL, 'modzzz_location', 'add', $iHandler) 
"); 


echo "SUCCESSFULLY UPDATED DATABASE ..... <br /><br />";


if ( !compileLanguage() )
{
	echo '<font color="red">RECOMPILE LANGUAGE FILES FAILED.</font><br /><br />'; 
}else{ 
	echo "SUCCESSFULLY RECOMPILED LANGUAGE FILES<br /><br />";
}


echo "FINISHED <br />";


?>